package com.mrzhou.gateway.provider;

import com.mrzhou.core.tool.constants.ApplicationConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * @author qiang.zhou
 */
public class ResponseProvider {

    /**
     * 成功
     */
    public static Map<String, Object> success(String msg) {
        return response(200, msg);
    }

    /**
     * 未授权
     */
    public static Map<String, Object> unAuth(String msg) {
        return response(401, msg);
    }

    /**
     * 服务器500错误
     */
    public static Map<String, Object> error(String msg) {
        return response(500, msg);
    }

    /**
     * 在接口报错时统一返回一致的JSON格式的数据
     * @param status
     * @param msg
     * @return
     */
    public static Map<String, Object> response(int status, String msg) {
        Map<String, Object> result = new HashMap<>(4);
        result.put(ApplicationConstant.R_CODE, status);
        result.put(ApplicationConstant.R_MSG, msg);
        result.put(ApplicationConstant.R_DATA, null);
        result.put(ApplicationConstant.R_SUCCESS, false);
        return result;
    }

}
